package com.diandian.backend.store.service;

import com.diandian.backend.store.domain.StoreJingdongHomeStoreInfo;
import com.diandian.backend.store.dto.*;
import com.diandian.backend.store.mapper.StoreJingdongHomeStoreInfoMapper;
import com.diandian.backend.store.resp.StoreJingdongHomeStoreInfoDetailResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;

@Service
public class StoreJingdongHomeStoreInfoService {

    @Autowired
    private StoreJingdongHomeStoreInfoMapper storeJingdongHomeStoreInfoMapper;

    public StoreJingdongHomeStoreInfoDetailResp getDetail(StoreJingdongHomeStoreInfoDetailParamDTO param) {

        StoreJingdongHomeStoreInfo dbData = storeJingdongHomeStoreInfoMapper.getDetail(param);
        if(dbData == null){
            return null;
        }

        StoreJingdongHomeStoreInfoDetailResp result = new StoreJingdongHomeStoreInfoDetailResp();
        result.setId(dbData.getId());
        result.setOfflineCode(dbData.getOfflineCode());
        result.setOnlineCode(dbData.getOnlineCode());
        result.setOnlineName(dbData.getOnlineName());
        result.setStauts(dbData.getStauts());
        result.setPhone(dbData.getPhone());
        result.setCity(dbData.getCity());
        result.setCountry(dbData.getCountry());
        result.setAddressDetail(dbData.getAddressDetail());
        result.setOperator(dbData.getOperator());
        result.setLat(dbData.getLat());
        result.setLng(dbData.getLng());
        result.setDeliveryRangeType(dbData.getDeliveryRangeType());
        result.setCoordinateType(dbData.getCoordinateType());
        result.setStandByPhone(dbData.getStandByPhone());
        result.setServiceStartTime(dbData.getServiceStartTime());
        result.setServiceEndTime(dbData.getServiceEndTime());
        result.setDeliveryRangeRadius(dbData.getDeliveryRangeRadius());
        result.setCoordinatePoints(dbData.getCoordinatePoints());
        result.setBelong(dbData.getBelong());
        result.setRemark(dbData.getRemark());
        result.setCreateUserId(dbData.getCreateUserId());
        result.setCreateUserName(dbData.getCreateUserName());
        result.setCreateTime(dbData.getCreateTime());
        result.setOrgId(dbData.getOrgId());
        result.setOrgCode(dbData.getOrgCode());
        result.setUpdateUserId(dbData.getUpdateUserId());
        result.setUpdateUserName(dbData.getUpdateUserName());
        result.setUpdateTime(dbData.getUpdateTime());
        result.setDel(dbData.getDel());
        return result;
    }

    public void updateBasicInfo(StoreJingdongHomeStoreInfoUpdateByIdParamDTO param) {
        param.check();
        storeJingdongHomeStoreInfoMapper.updateBasicInfo(param);
    }

    public void deleteById(StoreJingdongHomeStoreInfoDeleteByIdParamDTO paramDTO) {
        paramDTO.check();
        storeJingdongHomeStoreInfoMapper.deleteById(paramDTO);
    }

    public void add(StoreJingdongHomeStoreInfoAddParamDTO param) {
        param.setCreateTime(new Date());
        param.setDel(0);
        storeJingdongHomeStoreInfoMapper.add(param);
    }
}
